//
//  SVGVideoElement.m
//  Shake and Bake
//
//  Created by Antoine Quint on 05/11/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "SVGElement.h"
#import "SVGVideoElement.h"
#import "Canvas.h"

@implementation SVGVideoElement

- (id)initWithAttributeDict:(NSDictionary *)attributesDict andView:(Canvas *)aView
{
  [super initWithAttributeDict:attributesDict andView:aView];
	if (self) {
		// parse attribute values
		x = [[attributes objectForKey:@"x"] floatValue];
		y = [[attributes objectForKey:@"y"] floatValue];
		width = [[attributes objectForKey:@"width"] floatValue];
		height = [[attributes objectForKey:@"height"] floatValue];
		filePath = [attributes objectForKey:[view getQNameForAttribute:ATTRIBUTE_NAME_HREF inNamespace:NS_URI_XLINK]];				
		// flip to use proper coordinates
    self.sublayerTransform = CATransform3DMakeScale(1.0f, -1.0f, 1.0f);
		self.name = @"video";
    // init movie
    NSError	*error;
    movie = [QTMovie movieWithFile:filePath error:&error];
    if (movie) {
      movieLayer = [QTMovieLayer layerWithMovie:movie];
      movieLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
      [self addSublayer:movieLayer];
      [movie play];
    }
  }
  return self;
}

@end
